Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
decamelize
Advanced tools
Convert a camelized string into a lowercased one with a custom separator: unicornRainbow → unicorn_rainbow
The decamelize npm package is used to convert a string from camelCase to a lower case string with a custom separator (defaulting to an underscore). It is useful for transforming variable names or keys in objects from camelCase to a format that is more common in other languages or contexts, such as snake_case for database fields or kebab-case for CSS class names.
Decamelize a string
Converts 'myCamelCaseString' to 'my_camel_case_string' using the default separator.
"myCamelCaseString".decamelize()
Decamelize with a custom separator
Converts 'myCamelCaseString' to 'my-camel-case-string' using a custom separator ('-').
"myCamelCaseString".decamelize('-')
Preserve consecutive uppercase characters
Converts 'myURLString' to 'my_url_string', preserving the consecutive uppercase characters.
"myURLString".decamelize('_', { preserveConsecutiveUppercase: true })
The snake-case package converts strings to snake_case. It is similar to decamelize but is specifically tailored to produce snake_case without providing options for custom separators.
The kebab-case package is designed to convert strings to kebab-case. While it serves a similar purpose in changing the case of strings, it is focused on kebab-case rather than providing a customizable separator.
The change-case package is a more comprehensive string transformation library that includes a variety of case conversion functions, including decamelize. It offers a broader set of functionalities compared to the single-purpose decamelize package.
Convert a camelized string into a lowercased one with a custom separator
Example:unicornRainbow
→unicorn_rainbow
If you use this on untrusted user input, don't forget to limit the length to something reasonable.
$ npm install decamelize
const decamelize = require('decamelize');
decamelize('unicornRainbow');
//=> 'unicorn_rainbow'
decamelize('unicornRainbow', {separator: '-'});
//=> 'unicorn-rainbow'
decamelize('testGUILabel', {preserveConsecutiveUppercase: true});
//=> 'test_GUI_label'
decamelize('testGUILabel', {preserveConsecutiveUppercase: false});
//=> 'test_gui_label'
Type: string
Type: object
Type: string
Default: '_'
Character or string inserted to separate words in string
.
cosnt decamelize = require('decamelize');
decamelize('unicornRainbow');
//=> 'unicorn_rainbow'
decamelize('unicornRainbow', {separator: '-'});
//=> 'unicorn-rainbow'
Type: boolean
Default: false
Preserve sequences of uppercase characters.
const decamelize = require('decamelize');
decamelize('testGUILabel');
//=> 'test_gui_label'
decamelize('testGUILabel', {preserveConsecutiveUppercase: true});
//=> 'test_GUI_label'
See camelcase
for the inverse.
FAQs
Convert a camelized string into a lowercased one with a custom separator: unicornRainbow → unicorn_rainbow
We found that decamelize demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.